<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
    <th:block th:include="include :: header('修改部门')"/>
</head>
<body class="white-bg">
<div class="wrapper wrapper-content animated fadeInRight ibox-content">
    <form class="form-horizontal m" id="form-dept-edit">
        <input id="treeId" name="codeparent" type="hidden" th:value="${sort.codeparent}"/>

        <div class="form-group">
            <label class="col-sm-3 control-label">上级部门：</label>
            <div class="col-sm-8">
                <div class="input-group">
                    <input class="form-control" type="text" onclick="selectDeptTree()" id="treeName" readonly="true"
                           th:value="${parentName.sortname}">
                    <span class="input-group-addon"><i class="fa fa-search"></i></span>
                </div>
            </div>
        </div>
        <div class="row">
            <div class="col-sm-6">
                <div class="form-group">
                    <label class="col-sm-4 control-label is-required">分类编号：</label>
                    <div class="col-sm-8">
                        <input name="codepk" th:value="${sort.codepk}"  placeholder="内容分类ID" class="form-control" type="text" maxlength="30" required>
                    </div>
                </div>
            </div>
            <div class="col-sm-6">
                <div class="form-group">
                    <label class="col-sm-4 control-label">分类名称：</label>
                    <div class="col-sm-8">
                        <div class="input-group">
                            <input name="sortname" th:value="${sort.sortname}" id="deptName" required   type="text" placeholder="内容分类名称" class="form-control">
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <div class="row">
            <div class="col-sm-6">
                <div class="form-group">
                    <label class="col-sm-4 control-label is-required">排序值：</label>
                    <div class="col-sm-8">
                        <input name="ordnum" th:value="${sort.ordnum}"  placeholder="排序值" class="form-control" type="text" maxlength="30" required>
                    </div>
                </div>
            </div>
        </div>
    </form>
</div>
<th:block th:include="include :: footer"/>
<script type="text/javascript">
    var prefix = ctx + "system/content";


    $("#form-dept-edit").validate({
        onkeyup: false,
        rules: {
            deptName: {
                remote: {
                    url: prefix + "/checkAppealCateNameUnique",
                    type: "post",
                    dataType: "json",
                    data: {
                        "codepk": function () {
                            return $("#codepk").val();
                        },
                        "codeparent": function () {
                            return $("input[name='codeparent']").val();
                        },
                        "sortname": function () {
                            return $.common.trim($("#sortname").val());
                        }
                    },
                    dataFilter: function (data, type) {
                        return $.validate.unique(data);
                    }
                }
            },
            order_num: {
                digits: true
            },
            email: {
                email: true,
            },
            phone: {
                isPhone: true,
            },
        },
        messages: {
            "sortname": {
                remote: "内容已存在"
            }
        },
        focusCleanup: true
    });

    function submitHandler() {
        if ($.validate.form()) {
            $.operate.save(prefix + "/contentAppealCateEditJson", $('#form-dept-edit').serialize());
        }
    }

    /*部门管理-修改-选择部门树*/
    function selectDeptTree() {
        var deptId = $("#treeId").val();
        var excludeId = $("input[name='codepk']").val();
        if (deptId > 0) {
            var options = {
                title: '内容选择',
                width: "380",
                url: prefix + "/selectAppealCateTree/" + $("#treeId").val() + "/" + excludeId,
                callBack: doSubmit
            };
            $.modal.openOptions(options);
        } else {
            $.modal.alertError("父部门不能选择");
        }
    }

    function doSubmit(index, layero) {
        var tree = layero.find("iframe")[0].contentWindow.$._tree;
        if ($.tree.notAllowLastLevel(tree)) {
            var body = layer.getChildFrame('body', index);
            $("#treeId").val(body.find('#treeId').val());
            $("#treeName").val(body.find('#treeName').val());
            layer.close(index);
        }
    }
    function DropChgSendTextOnly(e,acpId) {
        document.getElementById(acpId).value = e.options[e.selectedIndex].text;
    }
</script>
</body>
</html>
